import useSetSearchParams from '@/hooks/useSetSearchParams';
import { ContentCard } from '@/page-components';
import { getUserDetail } from '@/services/demo/UserController';
import { Access, history, useAccess, useModel } from '@umijs/max';
import { Button, Modal, Select, Typography } from 'antd';
import { useEffect, useState } from 'react';
import {} from 'umi';

const AccessPage: React.FC = () => {
  const access = useAccess();
  const [count, setCount] = useState(0);
  const [value, setValue] = useState('1');
  const arr = [
    {
      label: '1',
      value: '1',
    },
    {
      label: '2',
      value: '2',
    },
  ];

  const getValue = () => {
    setTimeout(() => {
      Modal.confirm({
        title: value,
      });
    }, 3000);
  };
  const { setUrlParams, currUrlParams } = useSetSearchParams();

  const { userInfo, getInfo } = useModel('userInfo');
  useEffect(() => {
    getInfo();
    getDetail()
  }, []);

  const getDetail = async () => {
    const res = await getUserDetail({ userId: '1' });
    console.log(res);
  };
  return (
    <>
      <Access accessible={true}>
        <Button>只有 Admin 可以看到这个按钮</Button>
      </Access>
      权限测试页面
      <ContentCard title="权限测试页面">
        <Access accessible={true}>
          <Button>只有 Admin 可以看到这个按钮</Button>
        </Access>
        <Button onClick={() => history?.push('/access/test/detail/123')}>
          详情
        </Button>
        <Typography>
          <pre style={{ height: '300px', overflow: 'scroll' }}>
            {JSON.stringify(currUrlParams, null, 2)}
          </pre>
        </Typography>
        <Button onClick={() => getValue()}>count: {count}</Button>
        <Select
          options={arr}
          onChange={(value: any) => {
            setValue(value);
          }}
          value={value}
        />
        <Button
          onClick={() => {
            setCount(count + 1);
            setUrlParams((params: any) => {
              return {
                ...params,
                count: count + 1,
              };
            });
          }}
        >
          URL参数加1
        </Button>
      </ContentCard>
    </>
  );
};

export default AccessPage;
